#property copyright "Original Code by Laurence"
#property link      "http://www.forex-tsd.com/members/iZero.html"
// v1.2 MACD idea from spiritbreezer

// Modify and distribute as you like,
//  as long as it's still free.
// Even send me a copy with your changes
//  (see iZero from forex-tsd.com).

#property indicator_separate_window
#property indicator_buffers 7
//#property indicator_minimum -1
//#property indicator_maximum 1.2

extern string MA = "MA periods. 1 = No moving average";
extern int smoothMA = 5;
extern string MODES = "0 SMA, 1 EMA, 2 SMMA, 3 LWMA";
extern int smoothMODE = 0;
extern string MACDP = "If MODE = 4, MACD Periods";
extern int MACD1 = 5;
extern int MACD2 = 13;
extern int MACD3 = 1;
extern int Interval = 24;  //Bars to look for highest high and lowest low (max 100, min 1)
extern bool USD = 1;
extern bool EUR = 1;
extern bool GBP = 1;
extern bool CHF = 1;
extern bool JPY = 1;
extern bool AUD = 1;
extern bool CAD = 1;
extern color Color_USD = Green;
extern color Color_EUR = DarkBlue;
extern color Color_GBP = Red;
extern color Color_CHF = Chocolate;
extern color Color_JPY = Maroon;
extern color Color_AUD = DarkOrange;
extern color Color_CAD = Purple;

string Ind = "CrossCurrency v1.2";
int Objs = 0;

// indicator buffers
double arrUSD[];
double arrEUR[];
double arrGBP[];
double arrCHF[];
double arrJPY[];
double arrAUD[];
double arrCAD[];
double arrNZD[];

int CountedBars = 0;
double Range = 0.0001;

////////////////////////
int init()
{
   int cur = 50;
   int st = 80;
   int width = 0;

   if(smoothMA < 1) smoothMA = 1;
   if(smoothMODE > 4 || smoothMODE < 0) smoothMODE = 0;
   if(Interval > 100) Interval = 100; else if(Interval < 1) Interval = 1;

   if(USD) {
       sl("EURUSD", cur, Color_USD);
       cur += st;
     } else { Color_USD = -1; }
   if(EUR) {
       sl("EURJPY", cur, Color_EUR);
       cur += st;
     } else { Color_EUR = -1; }
   if(GBP) {
       sl("GBPUSD", cur, Color_GBP);
       cur += st;
     } else { Color_GBP = -1; }
   if(CHF) {
       sl("USDCHF", cur, Color_CHF);
       cur += st;
     } else { Color_CHF = -1; }
   if(JPY) {
       sl("USDJPY", cur, Color_JPY);
       cur += st;
     } else { Color_JPY = -1; }
   if(AUD) {
       sl("AUDUSD", cur, Color_AUD);
       cur += st;
     } else { Color_AUD = -1; }
   if(CAD) {
       sl("USDCAD", cur, Color_CAD);
       cur += st;
     } else { Color_CAD = -1; }

    IndicatorDigits(4);
    IndicatorShortName(Ind);

    SetIndexStyle(0, DRAW_LINE, DRAW_LINE, 2, Color_USD);
    SetIndexBuffer(0, arrUSD);
    SetIndexLabel(0, "USD");
    SetIndexStyle(1, DRAW_LINE, DRAW_LINE, 2, Color_EUR);
    SetIndexBuffer(1, arrEUR);
    SetIndexLabel(1, "EUR");
    SetIndexStyle(2, DRAW_LINE, DRAW_LINE, 2, Color_GBP);
    SetIndexBuffer(2, arrGBP);
    SetIndexLabel(2, "GBP");
    SetIndexStyle(3, DRAW_LINE, DRAW_LINE, 2, Color_CHF);
    SetIndexBuffer(3, arrCHF);
    SetIndexLabel(3, "CHF");
    SetIndexStyle(6, DRAW_LINE, DRAW_LINE, 2, Color_JPY);
    SetIndexBuffer(6, arrJPY);
    SetIndexLabel(6, "JPY");
    SetIndexStyle(4, DRAW_LINE, DRAW_LINE, 2, Color_AUD);
    SetIndexBuffer(4, arrAUD);
    SetIndexLabel(4, "AUD");
    SetIndexStyle(5, DRAW_LINE, DRAW_LINE, 2, Color_CAD);
    SetIndexBuffer(5, arrCAD);
    SetIndexLabel(5, "CAD");

    return(0);
}
////////////////////
int start()
{
   CountedBars = IndicatorCounted();
   if(CountedBars < 0) 
        return(-1);

   int nPos = Bars - CountedBars;
   double arr[];

   while(nPos > 0) {
      if(smoothMODE < 4) {
         if(USD) arrUSD[nPos] = doIt(nPos, "EURUSD");
         if(EUR) arrEUR[nPos] = doIt(nPos, "EURJPY");
         if(GBP) arrGBP[nPos] = doIt(nPos, "GBPUSD");
         if(CHF) arrCHF[nPos] = doIt(nPos, "USDCHF");
         if(JPY) arrJPY[nPos] = doIt(nPos, "USDJPY");
         if(AUD) arrAUD[nPos] = doIt(nPos, "AUDUSD");
         if(CAD) arrCAD[nPos] = doIt(nPos, "USDCAD");
      } else {
         if(USD) arrUSD[nPos] = iMACD("EURUSD", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(EUR) arrEUR[nPos] = iMACD("EURJPY", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(GBP) arrGBP[nPos] = iMACD("GBPUSD", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(CHF) arrCHF[nPos] = iMACD("USDCHF", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(JPY) arrJPY[nPos] = iMACD("USDJPY", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(AUD) arrAUD[nPos] = iMACD("AUDUSD", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
         if(CAD) arrCAD[nPos] = iMACD("USDCAD", 0, MACD1, MACD2, MACD3, PRICE_CLOSE, MODE_MAIN, nPos);
      }
      nPos--;
   }

}
double doIt(int pos, string curr) {
   double dClose = iMA(curr, 0, smoothMA, 0, smoothMODE, PRICE_CLOSE, pos);
   double dLow = iLow(curr, 0, iLowest(curr, 0, PRICE_LOW, Interval, pos));
   double dHigh = iHigh(curr, 0, iHighest(curr, 0, PRICE_HIGH, Interval, pos));

   double ret = (dClose - dLow) - (dHigh - dClose);

   if(dHigh - dLow > Range)
      ret /= dHigh - dLow;
   else
      ret /= Range;

   return(ret);   
}
void sl(string sym, int y, color col) {
   int window = WindowFind(Ind);
   string ID = Ind+Objs;
   int tmp = 10 + y;
   Objs++;
   if(ObjectCreate(ID, OBJ_LABEL, window, 0, 0))
     {
       ObjectSet(ID, OBJPROP_XDISTANCE, y + 35);
       ObjectSet(ID, OBJPROP_YDISTANCE, 0);
       ObjectSetText(ID, sym, 8, "Arial Black", col);
     }
}